package com.kvn.test.util;
/**
* @author wzy
* @date 2017年8月8日 下午5:03:11
*/
public abstract class PathUtil {
	
	/**
	 * 获取当前的 classes 绝对路径
	 * @return
	 */
	public static String getAbsoluteClassPath(){
		return PathUtil.class.getResource("/").getFile();
	}
	
	/**
	 * 获取绝对路径
	 * @param relativePath
	 * @return
	 */
	public static String getAbsoluteClassPath(String relativePath){
		return getAbsoluteClassPath() + relativePath;
	}
	
	/**
	 * 获取当前的 test-classes 绝对路径
	 * @return
	 */
	public static String getAbsoluteTestClassPath(){
		String absolutePrifix = PathUtil.class.getResource("/").getFile();
		if(absolutePrifix.endsWith("classes/")){
            absolutePrifix = absolutePrifix.substring(0, absolutePrifix.lastIndexOf("classes/")) + "test-classes/";
		} else {
			throw new RuntimeException("test-classes path not found");
		}
		
		return absolutePrifix;
	}
	
	public static String getAbsoluteTestClassPath(String relativePath){
		return getAbsoluteTestClassPath() + relativePath;
	}
	
	
	
	public static void main(String[] args) {
		System.out.println(PathUtil.getAbsoluteClassPath());
		System.out.println(PathUtil.getAbsoluteTestClassPath());
	}

}
